<?php
use services\models\Payment;
use yii\helpers\Url;
use services\models\OrderInfo;

?>

<?php $this->beginBlock('css');?>
  <link rel="stylesheet" type="text/css" href="<?= Yii::getAlias('@static')?>/pc/liketry/css/shop.css">
<?php $this->endBlock();?>


<div class="header-shop">
  <h1 class="logo left icon icon-logo-shop"><a href="<?=\Yii::$app->urlManager->createUrl(['index'])?>">有试吗</a></h1>
</div>

<div class="main">
	<div class="wxpay-top">
    	<div class="wxpay-orderid"><span>请您及时付款，以便订单尽快处理！订单号：</span><span><?=$order->order_sn?></span><span class="wxpay-sum">应付金额：<strong>¥<?=$order->order_amount?></strong>+<i><?=$order->try_coin?></i>试豆</span></div>
        <div class="wxpay-time-tips">为了保证及时处理您的订单，请于下单<strong>12</strong>小时内付款，若预期未付款订单将会被取消，需重新下单。<span class="wxpay-order-view">订单详情<span class="icon icon-arrow-down3"></span></span></div>
        <div class="wxpay-order-info">
        	收货地址：<?php
            /** @var \services\models\OrderExpress $addressInfo */
            $addressInfo = $order->orderExpress;
            echo $addressInfo->province, $addressInfo->city, $addressInfo->county, $addressInfo->address;
            ?> 收货人：<?=$addressInfo->consignee?> 手机号：<?=$addressInfo->mobile_phone?><br>
            商品名称：<br><?php
            /** @var \services\models\OrderGoods $goods */
            foreach($order->orderGoods as $goods):?>
                <?=$goods->goodsDetail->goods_name;?> <?php if($goods->productSpec):?>[<?=$goods->productSpec;?>]<?php endif;?><br>
            <?php endforeach;?>

        </div>
    </div>
    <div class="wxpay-main">
    	<h2>微信支付</h2>
        <div class="wxpay-scan">
       		<div class="wxpay-update-tips">距离二维码过期还剩<strong class="wxpay-rtime" id="rtime"></strong>，过期后请刷新页面重新获取二维码。</div>
            <div class="wxpay-qrcode"><img src="<?= Url::to(['order/qr','order_info_id'=>$order->order_info_id,'hashValue'=>Payment::getPaymentHash($order->order_info_id),'pay_method'=>OrderInfo::$PAY_TYPE_WEIXIN])?>" /></div>
            <div class="wxpay-scan-tips"></div>
        </div>
    </div>
</div>

<?php $this->beginBlock('js');?>
<script src="<?= Yii::getAlias('@static')?>/pc/common/js/jquery-1.12.3.min.js"></script> 
<script src="<?= Yii::getAlias('@static')?>/pc/common/js/lkt.pc.js"></script> 
<script src="<?= Yii::getAlias('@static')?>/pc/liketry/js/pay.js"></script>
<script>
var orderId="<?= Yii::$app->request->get("order_info_id")?>";
var payStatusUrl = '<?=Yii::$app->urlManager->createUrl(["order/pay-redirect",'order_info_id'=>'']);?>';
var payResultUrl = '<?=Yii::$app->urlManager->createUrl(["order/payed",'order_info_id'=>'']);?>';
$(function(){
	//返回顶部
	addGotop();
	rDate("#rtime",7199);
	var queryPayStatus = function(){
		$.doAjax({
			url: payStatusUrl + orderId,
			type: "post",
			success: function(data){
				if(data.flag){
					$.go(payResultUrl + orderId);
				}else{
					setTimeout(function(){
						queryPayStatus();
					},1500)
				}
			}
		});
	}
	queryPayStatus();
	//查看订单信息
	$(".wxpay-order-view").on("click", function(){
		var wxpayOrderInfo = $(".wxpay-order-info")
		wxpayOrderInfo.toggle();
		if(wxpayOrderInfo.is(":hidden")){
			$(this).children(".icon").attr("class","icon icon-arrow-down3");
		}else{
			$(this).children(".icon").attr("class","icon icon-arrow-up3");
		}
	})
})
</script>
<?php $this->endBlock();?>
